package com.fr.report.script.function;

import com.fr.base.FRContext;
import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import com.fr.report.script.core.FArray;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class SORTARRAY extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length != 1)
      return Primitive.ERROR_VALUE;
    Object localObject = paramArrayOfObject[0];
    if (!(localObject instanceof FArray))
      return Primitive.ERROR_VALUE;
    FArray localFArray = (FArray)localObject;
    ArrayList localArrayList = new ArrayList();
    for (int i = 0; i < localFArray.length(); ++i)
      localArrayList.add(localFArray.elementAt(i));
    try
    {
      Collections.sort(localArrayList);
    }
    catch (Exception localException)
    {
      FRContext.getLogger().log(Level.WARNING, localException.getMessage(), localException);
    }
    localFArray = new FArray(localArrayList);
    return localFArray;
  }

  public Function.Type getType()
  {
    return Function.ARRAY;
  }

  public String getCN()
  {
    return "SORTARRAY(array):返回数组array排过序的数组。\n示例：\nSORTARRAY([3, 4, 4, 5, 1, 5, 7])返回[1, 3, 4, 4, 5, 5, 7].\n注意：数组array的元素类型必须一样，并且要可比较。";
  }

  public String getEN()
  {
    return "";
  }
}